/**
 * 组件通讯的三种基本方式
 *
 * 父组件<=子组件
 *
 */

 import React from "react";

 class Parent extends React.Component {
   state = {
     lastName: "王",
     msg: ''
   };
 
   fn = (msg) => {
    console.log('子组件发来的消息', msg)
    this.setState({
        msg:msg
    })
   }
 
   render() {
     return (
       <div>
         <div>我是父组件，我姓：{this.state.lastName}{this.state.msg}</div>
         <Child lastName={this.state.lastName} fn={this.fn} />
       </div>
     );
   }
 }
 
 class Child extends React.Component {
 
     noMoney = () => {
       this.props.fn('没钱了！！！')
     }
 
 
   render() {
     return (
       <div>
         <div>我是子组件，我姓{this.props.lastName}</div>
         <button onClick={this.noMoney}>没钱了</button>
       </div>
     );
   }
 }
 
 export default Parent;
 